
function createChannel() {
    let currentTakers = [];
    /**
     * 监听异步动作，添加订阅
     * @param {*} actionType 动作类型 ASYNC_ADD
     * @param {*} taker 
     */
    function take(actionType, taker) {
        taker.actionType = actionType;
        taker.cancel = () => {
            currentTakers = currentTakers.filter(item => item !== taker);
        }
        currentTakers.push(taker);
    }
    /**
     * 执行函数，发布
     * @param {*} action { type: 'ASYNC_ADD' }
     */
    function put(action) {
        // taker就是next函数
        currentTakers.forEach(taker => {
            if (taker.actionType === action.type) {
                taker.cancel();
                taker(action);
            }
        });
    }
    return { take, put };
}

export default createChannel;
